package com.fish.admin.module.system.validator;

import com.fish.admin.module.system.domain.entity.SysRole;
import com.fish.admin.module.system.domain.entity.SysUser;
import com.fish.admin.module.system.manager.SysRoleManager;
import com.fish.admin.module.system.manager.SysUserManager;
import com.fish.common.core.enums.ReadonlyEnum;
import com.fish.common.support.context.SpringContextHolder;
import com.fish.common.support.util.AssertUtils;

import java.util.Objects;
import java.util.Optional;

public class SystemValidator {

    public static void validateRole(Long id) {
        SysRole sysRole = SpringContextHolder.getBean(SysRoleManager.class).getById(id);
        Optional.ofNullable(sysRole).ifPresent(s-> AssertUtils.isTrue(Objects.equals(s.getReadonly(), ReadonlyEnum.YES.getValue()), "系统用户角色，不允许操作!"));
    }

    public static void validateUser(Long id) {
        SysUser sysUser =  SpringContextHolder.getBean(SysUserManager.class).getById(id);
        Optional.ofNullable(sysUser).ifPresent(s->AssertUtils.isTrue(Objects.equals(s.getReadonly(), ReadonlyEnum.YES.getValue()), "系统用户，不允许操作!"));
    }


}
